﻿@page
@model LTQT.Pages.QuizModel
@{
}
<br />
<div style="margin:auto;height:45px;width:100%; color:#2b92f9;padding-bottom:10px" class="text-center">
    <h2>@Model.Quizs.FirstOrDefault(m => m.ID == Model.TQuizID).Name</h2>
</div>
<div style="width:95%; height:5px; border-bottom: 2px dashed; margin:auto; border-bottom-color:#808080;
    margin-bottom:10px"></div>
<div style="width:92%; margin:auto; color:#808080">@Model.Quizs.FirstOrDefault(m => m.ID == Model.TQuizID).Declaration</div>
<div style="width:95%; height:5px; border-bottom: 2px dashed; margin:auto; border-bottom-color:#808080;
    margin-top:10px"></div>

<div style="margin:auto; width:100%; text-align:center; margin-top:5px;
    background-color:#f4d9d9; color:red" id="time">剩余时间</div>
<br />

<form style="width:92%; margin:auto" method="post" enctype="multipart/form-data">
    @{
        int j = 0;
        @foreach (var question in Model.Questions)
        {
            @foreach (var answer in Model.Answer_Questions)
            {
                if (answer.QuestionID == question.ID && answer.Answer_QuizID == Model.Answer_Quiz.ID)
                {

                    if (question.IsExtension == 0)
                    {

                        if (question.IsChoose == 1)
                        {
                            <div id="@question.ID">
                                <label><font color="red">*</font>@question.Context</label>
                                <select asp-for="Answers[j]" class="form-control" id="sel_@question.Index">
                                    <option value="@answer.ANS">@answer.ANS</option>
                                    @foreach (var opt in Model.Question_Options)
                                    {
                                        if (answer.ANS != opt.Context && opt.QuestionID == question.ID)
                                        {
                                            <option value="@opt.Context">@opt.Context</option>
                                        }
                                    }
                                </select>
                            </div>
                        }
                        else
                        {
                            <div id="@question.ID">
                                <label><font color="green">*</font>@question.Context</label>
                                <input asp-for="Answers[j]" class="form-control" value="@answer.ANS" />
                            </div>
                        }
                    }
                    else
                    {
                        if (question.IsChoose == 1)
                        {
                            <div id="@question.ID" style="display:none">
                                <label><font color="green">*</font>@question.Context</label>
                                <select asp-for="Answers[j]" class="form-control">
                                    <option value="@answer.ANS">@answer.ANS</option>
                                    @foreach (var opt in Model.Question_Options)
                                    {
                                        if (answer.ANS != opt.Context && opt.QuestionID == question.ID)
                                        {
                                            <option value="@opt.Context">@opt.Context</option>
                                        }
                                    }
                                </select>
                            </div>
                        }
                        else
                        {
                            <div id="@question.ID" style="display:none">
                                <label><font color="green">*</font>@question.Context</label>
                                <input asp-for="Answers[j]" class="form-control" value="@answer.ANS" />
                            </div>
                        }
                    }
                    <div style="height:5px"></div>
                    j++;
                }

            }

        }
    }
    <input value="@Model.TQuizID" asp-for="TQuizID" hidden />
    <input value="@Model.Answer_Quiz.ID" asp-for="Answer_QuizID" hidden />
    <input value="@Model.User.ID" asp-for="UserID" hidden />
    <div class="row" style="margin-top:5px">
        <div class="col-4" style="padding-right:5px">
            <button style="color:white" type="submit" asp-page-handler="Save" class="btn btn-warning btn-block btn-lg">保存</button>
        </div>
        <div class="col-8" style="padding-left:5px">
            <button id="submit" type="submit" asp-page-handler="Submit" class="btn btn-primary btn-block btn-lg">提交</button>
        </div>
    </div>

</form>

<script src="~/lib/jquery/dist/jquery.min.js"></script>

@for (int i = 1; i <= Model.Questions.Count; i++)
{
    if (Model.Questions.FirstOrDefault(m => m.Index == i) == null)
    {
        continue;
    }
    var question = @Model.Questions.FirstOrDefault(m => m.Index == i);
    if (question.IsExtension == 0)
    {
        int ch1 = 0;
        foreach (var que in Model.Questions)
        {
            foreach (var ext in Model.Extension_Relations)
            {
                if (ext.ParentID == question.ID && ext.IsRightExtension == 1)
                {
                    ch1 = ext.ChildrenID;
                    break;
                }
            }
        }
        int ch2 = 0;
        foreach (var que in Model.Questions)
        {
            foreach (var ext in Model.Extension_Relations)
            {
                if (ext.ParentID == question.ID && ext.IsRightExtension == 0)
                {
                    ch2 = ext.ChildrenID;
                    break;
                }
            }
        }
<script>
        var rightANS = "@question.ANS";
        if ($("#sel_@i").val() == rightANS) {
            $("#@ch1").show();
            $("#@ch2").hide();
        } else if ($("#sel_@i").val() == " ") {
            $("#@ch1").hide();
            $("#@ch2").hide();
        } else {
            $("#@ch1").hide();
            $("#@ch2").show();
        }
        $(function () {
            $("#sel_@i").change(function () {
                rightANS = "@question.ANS";
                console.log($("#sel_@i").val())
                console.log(rightANS)
                if ($("#sel_@i").val() == rightANS) {
                    console.log(222)
                    $("#@ch1").show();
                    $("#@ch2").hide();
                } else if ($("#sel_@i").val() == " ") {
                    console.log(222)
                    $("#@ch1").hide();
                    $("#@ch2").hide();
                } else {
                    console.log(333)
                    $("#@ch1").hide();
                    $("#@ch2").show();
                }
            })
        })
</script>


}

}

<script>
    var setTime = parseInt("@Model.Answer_Quiz.StartTime.Ticks");
    setTime = parseInt((setTime - 621355968000000000) / 10000000 + 259200);
    function displayTime() {
        var nowTime = Date.parse(new Date()) / 1000;
        var delta = setTime - nowTime;
        if (delta < 0) {
            $("#submit").trigger("click");
        }
        var h = parseInt(delta / 3600);
        var m = parseInt(delta / 60) % 60;
        var ss = delta % 60;
        var s = "剩余时间：" + h + "小时" + m + "分钟" + ss + "秒";
        $("#time").html(s)
    }
    window.setInterval("displayTime()", 1000);
</script>

